package cc.git.liuyan.test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class Ys_Test_1 {
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.edge.driver", "E:\\edgeDriver\\msedgedriver.exe");
        EdgeOptions edgeOptions = new EdgeOptions();
        //edgeOptions.addArguments("--headless"); //无头模式
        edgeOptions.addArguments("--remote-allow-origins=*");
        WebDriver driver = new EdgeDriver(edgeOptions);
        WebDriverWait defaultWait = new WebDriverWait(driver, Duration.ofSeconds(10));
        //
        driver.get("http://ntbms.yshlw.com/login");
        //
        getWebElement(defaultWait, "//*[@id=\"form_item_account\"]").sendKeys("17500000000");
        getWebElement(defaultWait, "//*[@id=\"form_item_password\"]").sendKeys("123456A");
        //
        System.out.println(getWebElement(defaultWait, "//*[@id=\"app\"]/div/div[2]/div[2]/form/button").getText());
        //点击登录跳转到新页面
        getWebElement(defaultWait, "//*[@id=\"app\"]/div/div[2]/div[2]/form/button").click();

//        Thread.sleep(5000L); //一般不用

        WebElement webElement = getWebElement(defaultWait, "//*[@id=\"app\"]/div[2]/div[1]/ul/div/div[7]/li/div/span[2]");
        System.out.println(webElement.getText());
        webElement.click();

//        driver.quit();
        System.out.println("Hello, World!");
        System.exit(0);
    }

    public static WebElement getWebElement(WebDriverWait wait, String xpath) {
        return wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
    }
}